/**
 * Project Name:my_project
 * File Name:RefreshUtils.java
 * Package Name:com.lvman.utils
 * Date:2015年1月23日上午9:36:13
 * Copyright (c) 2015.
 *
 */

package com.jams.goodox.utils;


import android.content.Context;
import android.view.View;

import com.jams.goodox.R;

import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;
import in.srain.cube.views.ptr.header.MaterialHeader;

/**
 * ClassName:RefreshUtils <br/>
 * Function: 刷新的相关初始化工作 Reason:  ADD REASON. <br/>
 * Date: 2015年1月23日 上午9:36:13 <br/>
 * 
 * @author Administrator
 * @version
 * @since JDK 1.6
 * @see
 */
public class RefreshUtils {

	public static void initRefresh(Context c, MaterialHeader header, PtrFrameLayout frame) {
		int[] colors = c.getResources().getIntArray(R.array.progress_colors);
		header.setColorSchemeColors(colors);
		header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
		header.setPadding(0, DensityUtil.dp2px(c, 15.0f), 0, DensityUtil.dp2px(c, 10.0f));
		header.setPtrFrameLayout(frame);
		frame.setLoadingMinTime(1000);
		frame.setDurationToCloseHeader(500);
		frame.setHeaderView(header);
		frame.addPtrUIHandler(header);
		frame.disableWhenHorizontalMove(true);
	}



	public static void init(PtrFrameLayout refresh_layotut, final OnRefreshListener onRefresh){
		MaterialHeader header = new MaterialHeader(refresh_layotut.getContext());
		initRefresh(refresh_layotut.getContext(), header, refresh_layotut);
		refresh_layotut.setPtrHandler(new PtrHandler() {
			@Override
			public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
				return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
			}

			@Override
			public void onRefreshBegin(PtrFrameLayout frame) {
				if (onRefresh != null){
					onRefresh.onRefresh(frame);
				}
			}
		});

	}


public interface OnRefreshListener{
		void onRefresh(PtrFrameLayout frame);
	}


}
